<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/static/include/topLess.jsp"%>
<script>document.title="录入指标";</script>

<script src="${baseURL}/static/js/jquery.easyui.min.js"></script>
<link href="${baseURL}/static/js/themes/default/easyui.css" rel="stylesheet" type="text/css" />

<c:set var="userAreaId" value="${sessionScope.user.userAreaId}"></c:set>
<c:set var="pid" value="${requestScope.areasMap[sessionScope.user.userAreaId].parentId}"></c:set>

<table id="search_t" style="width:98%">
		<tbody>
			<tr style="display:none">
				<th><img src="${ctx}/static/images/pages/cen/rig/ico_01.png" align="middle">&nbsp;指标数据维护
				</th>
			</tr>
			<tr class="tab_grey">
				<td>
					<input type="hidden" id="areaId" name="areaId" value="${userAreaId}">
					选择条件：
					
					<input id="country" name="country" type="checkbox" value="0">&nbsp;全国
				<c:choose>
					<c:when test="${pid eq '0'}">
						<span class="tab_text">省(自治区、直辖市):</span>
					</c:when>
					<c:when test="${requestScope.areasMap[pid].parentId eq '0'}">
						<span class="tab_text">地(区、市、州、盟):</span>
					</c:when>
					<c:otherwise>
						<span class="tab_text">县(区、市、旗):</span>
					</c:otherwise>
				</c:choose>
				
				<select class="tab_textbut">
					<option value="${userAreaId}">${sessionScope.user.userAreaName}</option>
				</select>
				
				<c:if test="${pid eq '0'}">
					<span class="tab_text">地(区、市、州、盟):</span>
					<select class="tab_textbut" id="areaId2" onchange="queryAreasByParent(this)">
						<option value="">请选择..</option>
						<option value="${requestScope.areasMap['320600000000000'].id}">${requestScope.areasMap['320600000000000'].areaName}</option>
						<option value="${requestScope.areasMap['320700000000000'].id}">${requestScope.areasMap['320700000000000'].areaName}</option>
						<option value="${requestScope.areasMap['320900000000000'].id}">${requestScope.areasMap['320900000000000'].areaName}</option>
					</select>
				</c:if>
				<br/>
				<c:if test="${pid eq '0' || requestScope.areasMap[pid].parentId eq '0'}">
					<span class="tab_text">县(区、市、旗):</span>
					<select class="tab_textbut_100" id="areaId3">
						<option value="">请选择..</option>
						
						<c:if test="${requestScope.areasMap[pid].parentId eq '0'}">
							<c:forEach items="${requestScope.areasMap}" var="area">
								<c:if test="${requestScope.areasMap[pid].id eq area.value.parentId}">
								<option value="${area.value.id}">${area.value.areaName}</option>								
								</c:if>
							</c:forEach>
						</c:if>
						
					</select>
				</c:if>
				<span class="tab_text">上报频率：</span>
				<select id="timeType" name="timeType" class="tab_textbut">
					<option value="">请选择..</option>
					<option value="1">年报</option>
					<option value="3">半年报</option>
					<option value="2">季报</option>
				</select>
				<select id="quarter" name="endYear" class="tab_textbut" style="display: none">
					<option value="1">第一季度</option>
					<option value="2">第二季度</option>
					<option value="3">第三季度</option>
					<option value="4">第四季度</option>
				</select>
				<span class="tab_text">年份:</span>
				<select id="year" name="year" class="tab_textbut">
					<option value="">请选择..</option>
				</select>        

				<br/>

				<span class="tab_text">指标项:</span>
				<input type="text" class="tab_textbut_200" id="indicatorName" name="indicatorName" readonly onclick="indicatorSelect(); return false;">
				<input type="hidden" id="indicatorId" name="indicatorId">
				<span class="tab_text">指标值:</span>
				<input type="text" class="tab_textbut" id="indicatorValue" name="indicatorValue" >
				</td>
			</tr>
		</tbody>
		<tfoot>
			<tr>
				<td style="text-align:center">
				<a class="tab_but" href="#" onclick="addIndicator();return false;">添加</a>
				<a class="tab_but" href="#" onclick="closeWin()">关闭</a>
				</td>
			</tr>
		</tfoot>
</table>

<script language="javaScript">

	$().ready(function(){
		
		var startYear = ${requestScope.versionYearList.startYear};
		var endYear = ${requestScope.versionYearList.endYear};
		
		for (var i=startYear; i<=endYear + 5; i++){
			$("#year").append("<option>" + i + "</option>");
		}
		
		$("#year").val("2015");
		
		$("#timeType").bind("change", function(){
			if (this.value=="2"){	//季报
				$("#quarter").show();
			}else{
				$("#quarter").hide();
			}
		});
	});
	
	function validate(){

		if ($("#timeType").val()==""){
			layer.alert("请选择上报频率");
			return;
		}
		
		if ($("#year").val()==""){
			layer.alert("请选择年份");
			return;
		}	
		
		if ($("#indicatorName").val()==""){
			layer.alert("请选择指标项");
			return;
		}
		
		if ($("#indicatorValue").val()==""){
			layer.alert("请填写指标值");
			return;
		}
		
		var exp = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
		
		if (!exp.test($("#indicatorValue").val())){
			layer.alert("请输入正确格式的数字，并且只能有两位小数");
			return;
		}
		
		$("#areaId").val("${userAreaId}");
		
		if ($("#areaId2").val()!="" && $("#areaId2").val() != undefined){
			$("#areaId").val($("#areaId2").val());
		}
		
		if ($("#areaId3").val()!="" && $("#areaId3").val() != undefined){
			$("#areaId").val($("#areaId3").val());
		}
		
		if ($("input:checkbox:checked").val()){
			$("#areaId").val("0");	
		}
		return true;
	}
	
	//保存指标值方法
	function addIndicator(){

		if (!validate()){
			return ;
		}
		var quarter;
		var indicatorValue = $("#indicatorValue").val();
		var timeType = $("#timeType").val();
		var yearType = 0;
		
		if(timeType==3){	//半年报
			yearType = 1;
		}else if (timeType==1){  //年报
			yearType = 2;
		}else if (timeType==2){	//如果为季报，获取季度信息
			quarter = $("#quarter").val();			
		}

		var data = {
			indicatorId:$("#indicatorId").val(),
			areaId:$("#areaId").val(),
			timeType:$("#timeType").val(),
			year:$("#year").val(),
			yearTime:yearType,
			quarter:quarter,
			indicatorValue:$("#indicatorValue").val(),
			createPreId:'${sessionScope.user.id}'
		};
		
		var url = "${baseURL}/audit/createIndicator";

		$.post(url, data, function(msg){
			layer.msg("新增成功", 1, 1, function(){
				closeWin();
			});
		}, 'json');

	}
	
	//指标项选择
	function indicatorSelect(){
		var url = "${baseURL}/audit/indicatorAddSelectToPage?index=" + parent.layer.getFrameIndex(window.name);
		openWin("指标项查询", url, 850, 450);
	}
	
	function queryAreasByParent(obj){
		$.getJSON("${baseURL}/area/queryAreasByParent/" + obj.value, function(json){
			$("#areaId3").empty();
			$("#areaId3").append("<option value=''>请选择..</option>");
			$.each(json, function(i, area){
				$("#areaId3").append("<option value='" + area.id + "'>" + area.areaName + "</option>");
			});
		});
	}
	
</script>




<%@ include file="/static/include/bottom.jsp"%>